<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <p>
        <label for="">用户名</label>
        <input type="text" id="txt1">
    </p>
    <p>
        <label for="">手机号</label>
        <input type="text" id="txt2">
    </p>
    <p>
        <label for="">密码</label>
        <input type="password" id="txt3">
    </p>
    <input type="button" id="btn" value="提交">
</body>
<script>
    var txt1 = document.getElementById('txt1')
    var txt2 = document.getElementById('txt2')
    var txt3 = document.getElementById('txt3')
    var btn = document.getElementById('btn')


    var rega = /[a-zA-z]/
    var regb = /[\u4e00-\u9fa5]/
    var reg1 = /^1[356789]\d{9}$/
    var reg2 = /^[0-9a-zA-Z\._-]{8,14}$/


    btn.onclick = function () {
        var num = 0;
        var str = txt1.value
        var res = str.split("")
        res.forEach(function (val, idx) {
            if (rega.test(val)) {
                num += 1
            } else if (regb.test(val)) {
                num += 2
            }
        });
        // console.log(num)
        if (num < 15 && str != ""){
            console.log(true)
        }else{
            alert("请输入14个英文或7个汉字")
        }
        if(reg1.test(txt2.value)){
            console.log("手机号正确")
        }else{
            alert("手机号错误")
        }
        if(reg2.test(txt3.value)){
            console.log("密码正确")
        }else{
            alert("密码错误")
        }
        
    }

</script>

</html>